{% extends 'base-layer.html' %}

{% load staticfiles %}

{% block css %}

{% endblock %}

{% block main %}
    <div class="box box-danger">
        <form class="form-horizontal" id="addForm" method="post">
            {% csrf_token %}
            <!-- 请查看下面知识点介绍中注释1：-->
            <input type="hidden" name='mac_addr' value="{{ macaddr }}"/>
            <div class="box-body">
                <fieldset>
                    <legend>
                        <h4>服务器信息/通道</h4>
                    </legend>
                    <div class="form-group has-feedback">
                        <label class="col-sm-2 control-label">服务器</label>
                        <div class="col-sm-3">
                            <select class="form-control select2" style="width:100%;" name="server">
                                <option value="">--请选择服务器--</option>
                                {% for server in server_list %}
                                    <option value="{{ server }}">{{ server }}</option>
                                {% endfor %}
                            </select>
                        </div>

                        <label class="col-sm-2 control-label">通道</label>
                        <div class="col-sm-3">
                            <select class="form-control select2" style="width:100%;" name="tunnel">
                                <option value="">--请选择通道--</option>
                                {% for tunnel in tunnel_list %}
                                    <option value="{{ tunnel }}">{{ tunnel }}</option>
                                {% endfor %}
                            </select>
                        </div>
                    </div>

                </fieldset>

            </div>
            <div class="box-footer ">
                <div class="row span7 text-center ">
                    <button type="button" id="btnCancel" class="btn btn-default margin-right ">重置</button>
                    <button type="button" id="btnSave" class="btn btn-info margin-right ">保存</button>
                </div>
            </div>

        </form>
    </div>

{% endblock %}

{% block javascripts %}
    <script type="text/javascript">
        /*点取消刷新新页面*/
        $("#btnCancel").click(function () {
            window.location.reload();
        });

        // 保存
        $('#btnSave').click(function () {
            var data = $('#addForm').serialize();
            $.ajax({
                type: $('#addForm').attr('method'),
                url: "{% url 'system:route-update' %}",
                data: data,
                cache: false,
                success: function (resp) {
                    var msg = resp.msg;
                    var code = resp.code;
                    if (code === 0) {
                        layer.alert(msg, {icon: 1}, function (index) {
                            parent.layer.closeAll();    // 关闭所有弹窗
                            window.location.reload();
                        });
                    } else {
                        layer.alert(msg, {icon: 5});
                    }

                    return;

                }
            });
        })
    </script>
{% endblock %}